<template>
  <div ref="homePage" class="all">
    <div class="one_year">
      <img src="static/images/bg1.png" alt="" class="bg_img" @click="open_alert('kekeshi://app.kekeshi.com/orders/single_create?item_type=mommy_school_combo&item_uuid=345-345-345-345&app_store_product_id=kksmommy', '1')">
      <img src="static/images/mamiclass_icon_qiang.png" alt="" class="icon" @click="open_alert('kekeshi://app.kekeshi.com/orders/single_create?item_type=mommy_school_combo&item_uuid=345-345-345-345&app_store_product_id=kksmommy', '1')">
    </div>
    <div class="two_year">
      <img src="static/images/bg2.png" alt="" class="bg_img" @click="open_alert('kekeshi://app.kekeshi.com/orders/single_create?item_type=mommy_school_combo&item_uuid=123-123-123-123&app_store_product_id=kksmommyhalf', '半')">
      <img src="static/images/mamiclass_icon_qiang.png" alt="" class="icon" @click="open_alert('kekeshi://app.kekeshi.com/orders/single_create?item_type=mommy_school_combo&item_uuid=123-123-123-123&app_store_product_id=kksmommyhalf', '半')">
    </div>
    <div class="alert_bg" ref="alert" @click="close_alert" v-show="alert_show"></div>
    <div class="alert_box" v-show="alert_show">
      <div class="alert_title">购买妈咪成长学堂{{year_text}}年期课程</div>
      <div class="alert_content_box">
        <div class="course_content">
          <div class="content_title">
            {{year_text}}年期课程
          </div>
          <div class="left_bottom">
            折合<span class="pink_tip">2.45元</span>/节课
          </div>
        </div>
        <div class="course_price">
          <div class="price">￥1588元</div>
          <div class="price_tip">立省￥2976元</div>
        </div>
      </div>
      <div class="alert_price">实付金额：<span class="true_price">￥588元</span></div>
      <a :href="now_url" style="text-decoration: none">
        <div class="buy_btn" @click="buy">立即购买</div>
      </a>
    </div>
  </div>
</template>

<script>
    export default {
        name: "BuyCourse",

      data() {
          return{
            clientHeight: '',
            alert_show: false,
            now_url: '',
            year_text: '',
          }
      },
      methods: {
        buy(){
          console.log('-----');
          console.log(this.now_url)
        },
        changeFixed(clientHeight) {
          this.$refs.alert.style.height = clientHeight + 'px';
        },
        close_alert() {
          this.alert_show = false;
        },
        open_alert(url, text) {
          this.alert_show = true;
          this.now_url = url;
          this.year_text = text;
        }
      },
      mounted() {
        // 获取浏览器可视区域高度
        this.clientHeight =   `${document.documentElement.clientHeight}`;          //document.body.clientWidth;
        //console.log(self.clientHeight);
        window.onresize = function temp() {
          this.clientHeight = `${document.documentElement.clientHeight}`;
        };
        window.buy = this.buy;
      },
      watch: {
        // 如果 `clientHeight` 发生改变，这个函数就会运行
        clientHeight: function () {
          this.changeFixed(this.clientHeight)
        }
      },
    }
</script>

<style scoped>
  .all{
    width: 100%;
    height: auto;
  }
  .buy_btn{
    width: calc(100% - 40px);
    margin-left: 20px;
    height: 50px;
    font-size: 16px;
    line-height: 50px;
    text-align: center;
    background: #FF7D7D;
    color: white;
    border-radius: 10px;
    margin-top:10px;
  }
  .true_price{
    color: #FF7D7D;
    font-size: 18px;
  }
  .alert_price{
    text-align: right;
    font-size: 16px;
    color: #333333;
    margin-top: 20px;
    margin-right: 20px;
  }
  .course_price{
    margin-right: 20px;
    text-align: right;
  }
  .price_tip{
    color:#999999;
    font-size:12px;
  }
  .price{
    margin-top: 30px;
    font-size: 20px;
    color: #333333;
  }
  .pink_tip{
    color: #FF7D7D;
  }
  .left_bottom{
    font-size: 14px;
    color: #333333;
    margin-top: 20px;
  }
  .content_title{
    font-size: 18px;
    color: #FF7D7D;
  }
  .course_content{
    margin-left: 10px;
    margin-top: 10px;
  }
  .alert_content_box{
    margin-top:20px;
    width: calc(100% - 40px);
    margin-left: 20px;
    height: 85px;
    border-radius: 10px;
    background: #efefef;
    display: flex;
    justify-content: space-between;
  }
  .alert_title{
    font-size: 18px;
    margin-top:20px;
    margin-left:20px;
  }
  .one_year,.two_year{
    width: 350px;
    margin-left: calc((100% - 350px) / 2);
    margin-top:10px;
    height:320px;
    position: relative;
  }
  .bg_img{
    width: 100%;
    position: absolute;
    top:0;
    left:0;
  }

  .icon{
    width:50px;
    position: absolute;
    bottom: 5px;
    left: calc((100% - 50px) / 2);
  }
  .alert_box{
    position: absolute;
    bottom:0;
    background: white;
    width: 100%;
    border-radius: 10px 10px 0 0;
    height: 275px;
    text-align: left;
  }
  .alert_bg{
    width: 100%;
    background: black;
    position: absolute;
    opacity: 0.5;
    top:0;
    left:0;
  }
</style>
